<template>
    <h2>添加投资信息</h2>
    <table class="table table-bordered">
        <tr>
            <td>投资项目名称</td>
            <td><input type="text" v-model="info.Iname"></td>
        </tr>
        <tr>
            <td>投资项目总金额</td>
            <td><input type="text" v-model="info.Ibudget"></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="SaveData" class="btn btn-primary">提交</button>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import "bootstrap/dist/css/bootstrap.min.css"

// 定义一个响应式对象来存储表单数据
const info = ref({
    Iname: '',
    Ibudget: ""
})

const router = useRouter();
// 提交表单的函数
const SaveData = () => {
    if (info.value.Iname == "") {
        alert("投资项目名称不能为空");
        return;
    }
    if (info.value.Ibudget == "") {
        alert("投资项目总金额不能为空");
        return;
    }
    //投资项目总金额必须大于0且小于1亿元
    if (Number(info.value.Ibudget) <= 0 || Number(info.value.Ibudget) >= 10000000) {
        alert("投资项目总金额必须大于0且小于1亿元");
        return;
    }
    axios.post("https://localhost:44387/api/Invests/AddInvestInfo", {
        I_Name: info.value.Iname,
        I_Budget: info.value.Ibudget
    })
        .then(res => {
            console.log(res);
            if (res.data>0) {
                alert("投资成功");
               
            } else {
                alert("投资失败");
            }
        })
        .catch(err => {
            console.log(err);
            alert("添加失败");
        })
}

</script>